# Strategy imports
from Goldenberry.optimization.ga.GbCrossoverMgr.BinaryCrossers import *
from Goldenberry.optimization.ga.GbCrossoverMgr.RealCrossers import *
from Goldenberry.optimization.ga.GbCrossoverMgr.CrossorverContext import CrossorverContext
from Goldenberry.optimization.base.GbSolution import GbIndividual
# Setup impors
from Goldenberry.optimization.ga.DataType.CrossoverParams import CrossoverParams
# Interfaces import
from Goldenberry.optimization.ga.GbCrossoverMgr.ICrossoverMgt import ICrossoverMgt
from Goldenberry.optimization.ga.GbCrossoverMgr.ICrossoverSetup import ICrossoverSetup

class Crosser(ICrossoverMgt, ICrossoverSetup):
    """description of class"""
    crossover_method = ""
    crossover_context = None

    def __init__(self):
        self.crossover_context = CrossorverContext()

    #Override methods of ICrossoverMgt
    def cross(self, parents):
        genotype1, genotype2 = self.crossover_context.cross(parents)
        offspring1 = GbIndividual(genotype = genotype1)
        offspring2 = GbIndividual(genotype = genotype2)
        return offspring1, offspring2

    def set_crossover(self, crossover_method):
        if crossover_method == 'OnePointBinaryCrossover':
           self.crossover_context.set_curr_crossover_str(OnePointBinaryCrossover())
        elif crossover_method == 'TwoPointBinaryCrossover':
           self.crossover_context.set_curr_crossover_str(TwoPointBinaryCrossover())
        elif crossover_method == 'OnePointRealCrossover':
           self.crossover_context.set_curr_crossover_str(OnePointRealCrossover())
        elif crossover_method == 'TwoPointRealCrossover':
           self.crossover_context.set_curr_crossover_str(TwoPointRealCrossover())
        elif crossover_method == 'UniformArithmeticalCrossoverAX':
           self.crossover_context.set_curr_crossover_str(UniformArithmeticalCrossoverAX())
        elif crossover_method == 'BlendCrossoverBLXA':
           self.crossover_context.set_curr_crossover_str(BlendCrossoverBLXA())
        elif crossover_method == 'BlendCrossoverBLXAB':
           self.crossover_context.set_curr_crossover_str(BlendCrossoverBLXAB())
        else:
           self.crossover_context.set_curr_crossover_str(HeuristicCrossoverWHX())

    #Override methods of ICrossoverSetup
    def set_crossover_method(self, crossover_method):
        self.crossover_method = crossover_method#CrossoverParams(crossover_method)

    def get_crossover_method(self):
        return self.crossover_method